﻿@using LanDBom.Models
@using LanDBom.Resources
@{
    ViewBag.Title = "Zuye";
    Layout = "~/Views/Shared/_Genertals.cshtml";
}
@section styles{
    <style>
        #big {
            margin-top: 20px;
        }

            #big div {
            }

            #big > div {
                margin-left: 20px;
            }

        #right_big > div {
            background-color: white;
            height: 500px
        }

        #ZY_GN_d1 > div {
            width: 47%;
            margin-left: 2.1%;
            padding: 20px 20px 20px 20px;
        }

        #ZY_GN_d1 > div {
            background-color: white;
        }

        #ZY_GN_d1 {
            margin-top: 20px;
        }

        #ZY_GN_s1 > div {
            border-radius: 10px;
            text-align: center;
            font-size: 125%;
            font-weight: bolder;
            line-height: 100px;
            width: 30%;
            height: 100px;
            margin-left: 2.5%;
            box-shadow: 5px 5px 2.5px #888888;
        }

        #ZY_GN_s1 {
            margin-top: 10px;
        }

        #ZY_GN_s1_1 {
            background-color: #ff000040;
        }

        #ZY_GN_s1_2 {
            background-color: #0000ff45;
        }

        #ZY_GN_s1_3 {
            background-color: #bdb7d29c;
        }

        .ZY_GN_d1_1_01 > div {
            margin-top: 15px;
            border-bottom: 0.5px solid black;
        }

        .ZY_GN_d1_1_01 {
            margin-top: 10px;
        }

        #ZY_GN_s0 {
            background-color: white;
            padding: 20px 20px 20px 20px;
        }

        span {
            text-align: left;
        }

        div {
            text-align: initial
        }
    </style>
}

<from>
    <div class="row" id="big">
        <div class="col-8" id="left_big">
            <div id="ZY_GN_s0">
                <div>
                    @*带输入测试测试1*@
                </div>
                <div class="row" id="ZY_GN_s1">
                    <div id="ZY_GN_s1_1">
                        @Resource.String1
                    </div>
                    @*<div id="ZY_GN_s1_2">
                        @Resource.String1
                    </div>
                    <div id="ZY_GN_s1_3">
                        @Resource.String1
                    </div>*@
                </div>
            </div>

            <div class="row" id="ZY_GN_d1">
                <div id="ZY_GN_d1_1">
                    <div>
                        @Resource.String2
                    </div>
                    <div class="ZY_GN_d1_1_01">
                        <div>
                            <div>@Resource.String3</div>
                            <div class="row">
                                <div class="col-5"><a href="/Home/Index" id="a_sqd">@Resource.String13>></a></div>
                            </div>
                        </div>
                        <div>
                            <div>@Resource.String4</div>
                            <div class="row">
                                <div class="col-5"><a href="#" id="a_xj">@Resource.String13>></a></div>
                            </div>
                        </div>
                        <div>
                            <div>@Resource.String6</div>
                            <div class="row">
                                <div class="col-5"><a href="#" id="a_pdf">@Resource.String13>></a></div>
                            </div>
                        </div>
                        <div>
                            <div>@Resource.String5</div>
                            <div class="row">
                                <div class="col-5"><a href="#" id="a_wtd">@Resource.String13>></a></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div id="ZY_GN_d1_2">
                    <div>
                        @Resource.String7
                    </div>
                    <div class="ZY_GN_d1_1_01">
                        <div>
                            <div>@Resource.String8</div>
                            <div class="row">
                                <div class="col-5"><a href="~/Application/CliView">@Resource.String13>></a></div>
                            </div>
                        </div>
                        <div>
                            <div>@Resource.String9</div>
                            <div class="row">
                                <div class="col-5"><a href="/Material/AddGS">@Resource.String13>></a></div>
                            </div>
                        </div>
                        <div>
                            <div>@Resource.String10</div>
                            <div class="row">
                                <div class="col-5"><a href="/Formations/Index">@Resource.String13>></a></div>
                            </div>
                        </div>
                        <div>
                            <div>@Resource.String11</div>
                            <div class="row">
                                <div class="col-5"><a href="/librays/Index">@Resource.String13>></a></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-3" id="right_big" style="overflow: scroll;height: 500px;">
            <span>@Resource.String14</span>
        </div>
    </div>
</from>


@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {

            

            var bm = $("#Login_bm").text()
            var sf = $("#Login_sf").text()
            // PresentationAgent()
            //转跳到创建细报价
            $(document).on("click", "#ZY_GN_s1_1", function () {
                if (bm == "业务") {
                    window.location.href = "/Application/Application"
                }
                else {
                    alert("权限不足")
                }
            })
            //转跳到询价
            $(document).on("click", "#a_xj", function () {
                if (bm == "采购") {
                    window.location.href = "/Procure/Overview"
                }
                else {
                    alert("权限不足")
                }
            })
            //转跳到打印申请单
            $(document).on("click", "#a_pdf", function () {
                if (bm == "业务") {
                    window.location.href = "/Home/Quotation_to_be_generated"
                }
                else {
                    alert("权限不足")
                }
            })
            //转跳到设计委托
            $(document).on("click", "#a_wtd", function () {
                if (bm == "设计") {
                    window.location.href = "/Contracts/Inspect_Contracts"
                }
                else {
                    alert("权限不足")
                }
            })


            //打印代办项目
            var DSJISN = $("#Login_bm").text();
            SHensjinf();
            PresentationAgent() 
            //if (DSJISN == "业务") {
            //    SHensjinf()
            //} else if (DSJISN == "设计") {
            //    PresentationAgent()
            //}
            function PresentationAgent() {
                $.ajax({
                    url: '/Home/Zuye',
                    type: 'POST',
                    data: { "state": 1 },
                    success: function (data) {
                        createBom(data)
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            }
            function SHensjinf() {
                var sjinf = $("#Login_N").text()
                $.ajax({
                    url: '/Home/Zuye',
                    type: 'POST',
                    data: { "state": 2, "jidnan": sjinf },
                    success: function (data) {
                        createSHem(data)
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            }
            function createBom(data) {
                console.log(data)
                if (data.length!=0) {
                    $("#right_big div").remove();
                    $.each(data, function (i, item) {
                        var x = item.Cl_juli
                        console.log(x, x == $("#Login_sf").text() || x == $("#Login_N").text())
                        if (x == $("#Login_sf").text() || x == $("#Login_N").text()) {
                            var $div = (`
                             <div style="height:100px">
                                 <div>您有一条来自${item.Fr_fl}的${item.De_tiji}代办</div>
                                 <div>申请单号:<span>${item.Fr_bian}</span></div>
                                 <div>发起时间:<span>${item.Fr_time}</span></div>
                                 <div>发起人:${item.Nd_jiage}<span style="display:none">${item.Fr_id}</span><span style="display:none">${item.Fr_fl}</span><a href="#" id="ZY_dbzt">立即查看>>></a></div>
                                 <hr />
                             </div>
                            `);
                            $("#right_big").append($div);
                        }
                    })
                }
            }
            function createSHem(data) {
                if (data.length!=0) {
                    $("#right_big div").remove();
                    $.each(data, function (i, item) {
                        var KN = $("#Login_sf").text()
                        var x = item.FFirst
                        var D = item.FTwo
                        var Y = item.FThree
                        if (x == KN || D == KN || Y == KN) {
                            var $div = (`
                             <div style="height:70px">
                                 <div>您有一条来自${item.FShenR}的<span>${item.FMIao}</span>代办</div>
                                 <div>发起人:${item.FShenR}
                                 <span style="display:none">${item.FJINF}</span>
                                 <span style="display:none">${item.FJINF}</span>
                                 <a href="#" id="XU_jia">立即查看>>></a></div>
                                 <hr />
                             </div>
                            `);
                            $("#right_big").append($div);
                        }
                    })
                }
            }
            $(document).on("click", "#XU_jia", function () {
                var sjjjN = $(this).parent().prev().children().text();
                var bain = $(this).prev().text();
                if (sjjjN =="询价审批") {
                    window.location.href = "/ShenPI/Index?bians=" + bain;
                } 
                if (sjjjN == "核价审批") {
                    window.location.href = "/ShenPI/HJSP?bians=" + bain;
                }
               
            })
            //修改代办状态
            function complete_plan(id) {
                var BZJG = [];
                BZJG.push({
                    Fr_id: id,
                    Fr_zhuang: "已处理"
                })
                console.log("共" + BZJG.length + "数据");
                console.log(BZJG);
                $.ajax({
                    url: "/Home/Modify_fre_zhuang",
                    type: 'POST',
                    data: JSON.stringify(BZJG),
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (text) {
                    },
                    error: function (text) {
                        alert("系统错误" + text);
                    }
                })
            }

            $(document).on("click", "#ZY_dbzt", function (e) {
                var index = $(e.target).prev().text()
                var id = $(e.target).prev().prev().text()
                var bain = $(e.target).parent().parent().children().eq(1).children().text();
                var name = $("#Login_N").text()
                console.log(name)
                complete_plan(id)
                if (index == "设计委托"||index == "报价发起") {
                    window.location.href = "/Application/Application?App_ban=" + bain + "&Nameed=" + name +"&name=设计委托";
                }
                else if (index == "采购" || index == "BOM重置") {
                    window.location.href = "/Procure/Overview"
                }
                else if (index == "申请单") {
                    window.location.href = "/Application/Requisition"
                } else if (index == "物料询价" || index == "物料核价") {
                    window.location.href = "/Application/Requisition_form"
                }
            })
        })
    </script>
}